package com.hxd.otc.module.fiat_deal.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.module.fiat_deal.bean.SelectFiatBean;
import com.hxd.otc.utils.ResourceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/9/17 0017.
 * description ${选择法币Adapter}
 */
public class SelectFiatAdapter extends BaseAdapter<SelectFiatAdapter.SelectFiatHolder, SelectFiatBean> {

    private String mSelectedFiat;

    public SelectFiatAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull SelectFiatHolder holder, int position) {
        SelectFiatBean item = getItem(position);
        holder.tvItem.setText(item.getFiat());
        holder.tvItem.setCompoundDrawables(ResourceUtil.getDrawable(item.getIcon()), null, null, null);
        holder.tvItem.setSelected(item.getFiat().equals(mSelectedFiat));
    }

    @NonNull
    @Override
    public SelectFiatHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SelectFiatHolder(mInflater.inflate(R.layout.item_select_fiat, parent, false));
    }

    public void setSelectedFiat(String selectedFiat) {
        mSelectedFiat = selectedFiat;
    }

    static class SelectFiatHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_item)
        TextView tvItem;

        SelectFiatHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
